//
//  ClassifyTableViewCell.m
//  MyNewProject
//
//  Created by 王春辉 on 2019/12/21.
//  Copyright © 2019年 sun. All rights reserved.
//

#import "ClassifyTableViewCell.h"

@interface ClassifyTableViewCell() {
    UIColor *_selectedColor; // 选中状态颜色
    UIColor *_defaultColor; // 默认状态颜色
}
@property (nonatomic, strong) UIView *statusView;
@end
@implementation ClassifyTableViewCell
@synthesize titleLabel = _titleLabel;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _selectedColor = SKColorWithHex(0xE33030);
        _defaultColor = SKColorWithHex(0x333333);
        [self setupContentViews];
    }
    return self;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = _defaultColor;
        _titleLabel.font = SKFONT_Semibold(14);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UIView *)statusView {
    if (!_statusView) {
        self.statusView = [[UIView alloc] init];
        _statusView.backgroundColor = _selectedColor;
        [self addSubview:_statusView];
    }
    return _statusView;
}
/**
 初始化views
 */
- (void)setupContentViews {
    [self.statusView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerY.mas_offset(0);
        make.height.mas_equalTo(14);
        make.width.mas_equalTo(3);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_offset(0);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.statusView.hidden = !selected;
    self.titleLabel.textColor = selected ? _selectedColor : _defaultColor;
}

@end
